// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dfa.axis.v1_15;

import com.google.api.ads.dfa.lib.client.DfaSession;
import com.google.api.ads.dfa.lib.factory.DfaServices;
import com.google.api.ads.dfa.axis.v1_15.CreativeRemote;
import com.google.api.ads.dfa.axis.v1_15.CreativeSaveResult;
import com.google.api.ads.dfa.axis.v1_15.ImageCreative;

/**
 * This example creates an image creative associated with a given advertiser.
 * Since no campaign is specified, the creative is created at the advertiser
 * level. To create image assets, run CreateImageAsset.java. To get a size ID,
 * run GetSize.java.
 *
 * Tags: creative.saveCreative
 *
 * @author Joseph DiLallo
 */
public class CreateImageCreative {

  public static void main(String[] args) throws Exception {
    long advertiserId = Long.parseLong("INSERT_ADVERTISER_ID_HERE");
    String creativeName = "INSERT_CREATIVE_NAME_HERE";
    String assetFileName = "INSERT_CREATIVE_ASSET_FILE_NAME_HERE";
    long sizeId = Long.parseLong("INSERT_SIZE_ID_HERE");

    // Initialize your session.
    DfaSession session = new DfaSession.Builder().fromFile().build();

    // Request the creative service from the service client factory.
    CreativeRemote creativeService = new DfaServices().get(session, CreativeRemote.class);

    // Create flash inpage structure.
    ImageCreative imageCreative = new ImageCreative();
    imageCreative.setId(0);
    imageCreative.setName(creativeName);
    imageCreative.setActive(true);
    imageCreative.setTypeId(1); // Hard-coded to "Image Creative" type.
    imageCreative.setAdvertiserId(advertiserId);
    imageCreative.setSizeId(sizeId);
    imageCreative.setAssetFilename(assetFileName);

    CreativeSaveResult creativeSaveResult = creativeService.saveCreative(imageCreative, 0);

    // Display new creative ID.
    System.out.printf("Flash inpage creative with ID \"%s\" was created.%n",
        creativeSaveResult.getId());
  }
}
